package cn.tom.service.impl;

import cn.tom.entity.Group;
import cn.tom.mapper.GroupMapper;
import cn.tom.service.GroupService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class GroupServiceImpl implements GroupService {
    @Autowired
    GroupMapper groupMapper;

    /**
     * 根据时间查询最新的6条团队信息
     */
    @Override
    public List<Group> findByDate() {
        List<Group> byDate = groupMapper.findByDate();
        return byDate;
    }

    /**
     * 根据团队ID查询
     */
    @Override
    public Group findById(Integer id) {
        LambdaQueryWrapper<Group> lqw = Wrappers.lambdaQuery();
        lqw.eq(id != null, Group::getId, id);
        Group group = groupMapper.findById(id);
        return group;
    }

    /**
     * 精英团队添加
     */
    @Override
    public int add(Group group) {
        group.setDay(new Date());  //给日期赋值
        int insert = groupMapper.insert(group);
        return insert;
    }

    /**
     * 精英团队更新
     */
    @Override
    public int update(Group group) {
        int i = groupMapper.updateById(group);
        return i;
    }

    /**
     * 根据团队ID删除
     */
    @Override
    public int del(Integer id) {
        int i = groupMapper.deleteById(id);
        return i;
    }
}
